package com.um.jdy.common.activity.service.impl;

import com.um.jdy.common.activity.entity.vo.CouponsAndStationVO;
import com.um.jdy.common.activity.enums.ActivityEnum;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.um.springboot.starter.orm.service.BaseEntityServiceImpl;
import com.um.jdy.common.activity.service.CouponsStationService;
import com.um.jdy.common.activity.dao.CouponsStationDao;
import com.um.jdy.common.activity.entity.po.CouponsStation;

import java.util.List;

/**
 * 服务实现类：优惠券站场关联表
 */
@Service
@Transactional
@Slf4j
public class CouponsStationServiceImpl extends BaseEntityServiceImpl<CouponsStationDao,CouponsStation>  implements CouponsStationService{

    /**
     * 站场是否有优惠券
     *
     * @param deviceStationId
     * @return
     */
    @Override
    public boolean hasCoupons(String deviceStationId, String memberUserId) {
        return getAllCoupons(memberUserId).stream().anyMatch(coupons ->
                ActivityEnum.UseRange.All.name().equals(coupons.getAvailable()) ||
                        coupons.getDeviceStationIdList().contains(deviceStationId));
    }

    /**
     * 查询所有优惠券
     * @return
     */
    @Override
    public List<CouponsAndStationVO> getAllCoupons(String memberUserId) {
        List<CouponsAndStationVO> list = dao.getViewModelList("get_all_coupons_and_station_id",
                CouponsAndStationVO.class, new String[]{memberUserId,getComId()});
        return list;
    }
}
